﻿using OA.Core;
using OA.Core.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace OA.Model.MyAttribute
{
    public class EnumAttribute : ValidationAttribute
    {
        public Type Type { get; set; }

        public EnumAttribute(Type type)
        {
            this.Type = type;
        }

        public override bool IsValid(object value)
        {
            int result;
            if(Int32.TryParse(value.ToString(),out result)){
                return false;
            }
            Dictionary<string,int> dic= EnumHelper.GetEnumKeyValue(Type);
            if (dic.ContainsValue(result)) return true;
            return false;
        }
    }
}
